package com.saicent.note.core.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.saicent.note.core.Article;
import com.saicent.note.core.ArticleLoader;

public class AutoArticleLoader extends AbstractArticleLoader {

	private List<String> locations = new ArrayList<>();
	
	public AutoArticleLoader(String configLocation) {
		String[] locationArray = configLocation.split(",");
		for (String location : locationArray) {
			locations.add(location.trim());
		}
	}
	
	@Override
	public Collection<Article> loadArticles() {
		List<Article> articles = new ArrayList<>();
		for (String location : locations) {
			articles.addAll(loadArticleFromDirectory(location));
		}
		return articles;
	}

	public static void main(String[] args) {
		ArticleLoader articleLoader = new AutoArticleLoader("/WEB-INF/view/notes");
		articleLoader.setWorkDirectory("/Users/linshuaishuai/LSS_WORKSPACE/JAVA/NOTE-CORE/webapp/");
		Collection<Article> articles = articleLoader.loadArticles();
		System.out.println(articles);
	}
}
